home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / prog / alertdrv.arj / ALERTDRV.H < prev    next >
C/C++ Source or Header  |  1994-01-25  |  19KB  |  461 lines

  1. #ifndef ALERTDRV_H
  2. #define ALERTDRV_H
  3.  
  4.  
  5.  
  6. /*------------------------------------------------------------------------------
  7.    Copyright           : (c)1994 by Logical Operators
  8.                          All Rights Reserved.
  9.    Filename            : AlertDrv.H
  10.    Header File         : AlertDrv.H
  11.    Purpose             : Header file for the AlertDriver classes. An
  12.                          AlertDriver object is used as a device driver by other
  13.                          objects. The controlling object can then alert the
  14.                          user of errors or program conditions by communicating
  15.                          through a descendant of an AlertDriver object,
  16.                          resulting in the device-independence of the
  17.                          controlling object.
  18.    Compiler Directives : None
  19.  
  20.    Modification History:
  21.    Version   Date    Programmer and Description of Changes
  22.    ------- --------  --------------------------------------------------------
  23.     1.00   01/18/94  Original version by Warren J. Hairston.
  24.    ---------------------------------------------------------------------------*/
  25.  
  26.  
  27.  
  28.    //included files
  29.    //--------------
  30.    #include <ENVIRON.H>   //contains platform-specific definitions
  31.  
  32.    #include <fstream.h>   //C++ file stream declarations
  33.    #include <string.h>     //strcpy() function prototype
  34.  
  35.  
  36.  
  37.    /* constants - Used to set the processing flags for an AlertDriver. The adf
  38.                   prefix denotes an AlertDriver Flag code. */
  39.    //--------------------------------------------------------------------------
  40.    const unsigned short adfERROR      = 0x01,   //process errors
  41.                         adfINFO       = 0x02,   //process info text
  42.                         adfMESSAGE    = 0x04,   //process messages
  43.                         adfWARNING    = 0x08,   //process warnings
  44.                         adfALLALERTS  = 0x0F,   //process all alerts
  45.                         adfTIMESTAMP  = 0x10,   //time-stamp text
  46.                         adfDISCLOSURE = 0x20;   /*return cause, not necessarily
  47.                                                   return value*/
  48.  
  49.  
  50.  
  51.    /* constants - These return codes represent user selections in some
  52.                   AlertDriver methods. The ads prefix denotes an AlertDriver
  53.                   Selection code. */
  54.    //--------------------------------------------------------------------------
  55.    const unsigned short adsCANCEL   = 0,   //CANCEL choice
  56.                         adsDISABLED = 1,   //processing flag disabled
  57.                         adsNO       = 2,   //NO choice
  58.                         adsNODRIVER = 3,   //no AlertDriver exists
  59.                         adsYES      = 4;   //YES choice
  60.  
  61.  
  62.  
  63.    /* constants - Options to indicate how AlertDriver::ChangeProcFlags() affects
  64.                   the flags for each AlertDriver in the chain. The cfo prefix
  65.                   denotes a Change Flag Option code. */
  66.    //--------------------------------------------------------------------------
  67.    const unsigned short cfoCHAIN     = 0x00,   /*specified flags should alter
  68.                                                  the processing flags of all
  69.                                                  AlertDrivers in the chain,
  70.                                                  starting with the AlertDriver
  71.                                                  to which the message was sent*/
  72.                         cfoDRIVER    = 0x01,   /*specified flags should alter
  73.                                                  only the processing flags of
  74.                                                  the AlertDriver to which the
  75.                                                  message was originally sent*/
  76.                         cfoOVERWRITE = 0x00,   /*copy specified flags to
  77.                                                 AlertDriver, possibly altering
  78.                                                 other proessing flags*/
  79.                         cfoENABLE    = 0x02,   /*enable only specified flags
  80.                                                  without altering other
  81.                                                  processing flags*/
  82.                         cfoDISABLE   = 0x04;   /*disable only specified flags
  83.                                                  without altering other
  84.                                                  processing flags*/
  85.  
  86.  
  87.  
  88.    /* constants - Options to indicate how RecordingAlertDriver objects should
  89.                   control their output device resources. The rad prefix indicates
  90.                   a RecordingAlertDriver code. */
  91.    //--------------------------------------------------------------------------
  92.    const short radHOLDRESOURCE = 0x00,   /*open resource during construction and
  93.                                            hold open until destruction*/
  94.                radFREERESOURCE = 0x01,   /*open resource just before output and
  95.                                            close resource after each output*/
  96.                radASISRESOURCE = 0x02;   /*use the resource as-is:  do not open
  97.                                            or close the resource*/
  98.  
  99.  
  100.  
  101.    //class declarations
  102.    //------------------
  103.    class AlertDriver;   /*defined below, declared here for reference in class
  104.                           AlertDriverLink*/
  105.  
  106.  
  107.  
  108.    class AlertDriverLink
  109.    #ifdef ROOTCLASS
  110.       : public ROOTCLASS
  111.    #endif   //ROOTCLASS
  112.    {
  113.       public:
  114.          //constructor(s)
  115.          //--------------
  116.          AlertDriverLink(void)
  117.          #ifdef ROOTCLASS
  118.             : ROOTCLASS()
  119.          #endif   //ROOTCLASS
  120.             {linkedAlertDriver = NULL;}
  121.  
  122.          //destructor
  123.          //----------
  124.          virtual ~AlertDriverLink() {FreeLinkedAlertDriver();}
  125.  
  126.          //member functions
  127.          //----------------
  128.          void         ChangeLinkedAlertDriver(AlertDriver *anAlertDriver);
  129.          AlertDriver* GetLinkedAlertDriver(void) const
  130.                          {return linkedAlertDriver;}
  131.  
  132.       protected:
  133.          //data members
  134.          //------------
  135.          AlertDriver *linkedAlertDriver;   /*Points to an AlertDriver which is
  136.                                              linked to this object. AlertDrivers
  137.                                              may be daisy-chained together to
  138.                                              allow multiple types of alerting.*/
  139.  
  140.          //member functions
  141.          //----------------
  142.          virtual void FreeLinkedAlertDriver(void);
  143.    };   //class AlertDriverLink
  144.  
  145.  
  146.  
  147.    class AlertDriver : public AlertDriverLink
  148.    {
  149.       public:
  150.          //constructor(s)
  151.          //--------------
  152.          AlertDriver(void);
  153.  
  154.          //destructor
  155.          //----------
  156.          virtual ~AlertDriver() {referenceCount = 0;}
  157.  
  158.          //member functions
  159.          //----------------
  160.                  unsigned long  Attach(void) {return ++referenceCount;}
  161.          virtual unsigned short ChangeProcFlags(const unsigned short newFlags,
  162.                                                 const unsigned short options =
  163.                                                    cfoCHAIN | cfoOVERWRITE);
  164.                  unsigned long  Detach(void) {return --referenceCount;}
  165.                  unsigned short GetProcFlags(void) const
  166.                                    {return processingFlags;}
  167.          virtual void           GetTimestamp(char *timestamp) const;
  168.                  void           HandleError(const char *text);
  169.                  void           HandleInfo(const char *text);
  170.                  void           HandleMessage(const char *text);
  171.                  unsigned short HandleWarning(const char *text,
  172.                                               const unsigned short
  173.                                                  defaultChoice);
  174.                  int            IsAttached(void) const
  175.                                    {return (referenceCount > 0);}
  176.                  unsigned long  NumAttached(void) const {return referenceCount;}
  177.  
  178.          //platform-specific member functions
  179.          //----------------------------------
  180.          #ifdef BORLAND_CONTAIN
  181.             virtual hashValueType hashValue() const {return 0;}
  182.             virtual classType     isA() const {return 0;}
  183.             virtual int           isEqual (const Object& testObject) const
  184.                                      {return 0;}
  185.             virtual char*         nameOf() const {return "AlertDriver";}
  186.             virtual void          printOn(ostream& outputStream) const {}
  187.          #endif   //BORLAND_CONTAIN
  188.  
  189.       protected:
  190.          //member functions
  191.          //----------------
  192.          virtual void           ReportError(const char *text) = 0;
  193.          virtual void           ReportInfo(const char *text) = 0;
  194.          virtual void           ReportMessage(const char *text) = 0;
  195.          virtual unsigned short ReportWarning(const char *text,
  196.                                               const unsigned short
  197.                                                  defaultChoice) = 0;
  198.  
  199.       private:
  200.          //data members
  201.          //------------
  202.          unsigned short processingFlags;   /*flags which control how this
  203.                                              AlertDriver responds during the
  204.                                              processing of member functions*/
  205.          unsigned long  referenceCount;    /*number of objects which are
  206.                                              currently referencing this
  207.                                              AlertDriver*/
  208.    };   //class AlertDriver
  209.  
  210.  
  211.  
  212.    class RecordingAlertDriver : public AlertDriver
  213.    {
  214.       public:
  215.          //constructor(s)
  216.          //--------------
  217.          RecordingAlertDriver(const short resourceControlMode) :
  218.             AlertDriver() {resourceControl = resourceControlMode;}
  219.  
  220.          //member functions
  221.          //----------------
  222.          short GetResourceControl(void) const {return resourceControl;}
  223.  
  224.          //platform-specific member functions
  225.          //----------------------------------
  226.          #ifdef BORLAND_CONTAIN
  227.             virtual char* nameOf() const {return "RecordingAlertDriver";}
  228.          #endif   //BORLAND_CONTAIN
  229.  
  230.       private:
  231.          //data members
  232.          //------------
  233.          short resourceControl;   /*determines if this object should hold the
  234.                                     resource or release it for use by other
  235.                                     objects or programs*/
  236.    };   //class RecordingAlertDriver
  237.  
  238.  
  239.  
  240.    class StdAlertDriver : public AlertDriver
  241.    {
  242.       public:
  243.          //platform-specific member functions
  244.          //----------------------------------
  245.          #ifdef BORLAND_CONTAIN
  246.             virtual char* nameOf() const {return "StdAlertDriver";}
  247.          #endif   //BORLAND_CONTAIN
  248.  
  249.       protected:
  250.          //member functions
  251.          //----------------
  252.          virtual void           ReportError(const char *text);
  253.          virtual void           ReportInfo(const char *text);
  254.          virtual void           ReportMessage(const char *text);
  255.          virtual unsigned short ReportWarning(const char *text,
  256.                                               const unsigned short
  257.                                                  defaultChoice);
  258.    };   //class StdAlertDriver
  259.  
  260.  
  261.  
  262.    class StreamAlertDriver : public RecordingAlertDriver
  263.    {
  264.       public:
  265.          //constructor(s)
  266.          //--------------
  267.          StreamAlertDriver(ostream &outputStream,
  268.                            const short resourceControlMode = radASISRESOURCE) :
  269.             RecordingAlertDriver(resourceControlMode), outStream(outputStream){}
  270.  
  271.          //member functions
  272.          //----------------
  273.          ostream& GetStream(void) const {return outStream;}
  274.  
  275.          //platform-specific member functions
  276.          //----------------------------------
  277.          #ifdef BORLAND_CONTAIN
  278.             virtual char* nameOf() const {return "StreamAlertDriver";}
  279.          #endif   //BORLAND_CONTAIN
  280.  
  281.       protected:
  282.          //data members
  283.          //------------
  284.          ostream &outStream;   //references the stream to be used for output
  285.  
  286.          //member functions
  287.          //----------------
  288.          virtual void           ReportError(const char *text);
  289.          virtual void           ReportInfo(const char *text);
  290.          virtual void           ReportMessage(const char *text);
  291.          virtual unsigned short ReportWarning(const char *text,
  292.                                               const unsigned short
  293.                                                  defaultChoice);
  294.    };   //class StreamAlertDriver
  295.  
  296.  
  297.  
  298.    class TextFileAlertDriver : public StreamAlertDriver
  299.    {
  300.       public:
  301.          //constructor(s)
  302.          //--------------
  303.          TextFileAlertDriver(const char *filename,
  304.                              const short resourceControlMode);
  305.  
  306.          //destructor
  307.          //----------
  308.          virtual ~TextFileAlertDriver();
  309.  
  310.          //member functions
  311.          //----------------
  312.          void GetFilename(char *filename) const {strcpy(filename, adFilename);}
  313.  
  314.          //platform-specific member functions
  315.          //----------------------------------
  316.          #ifdef BORLAND_CONTAIN
  317.             virtual char* nameOf() const {return "TextFileAlertDriver";}
  318.          #endif   //BORLAND_CONTAIN
  319.  
  320.       protected:
  321.          //member functions
  322.          //----------------
  323.          virtual void           ReportError(const char *text);
  324.          virtual void           ReportInfo(const char *text);
  325.          virtual void           ReportMessage(const char *text);
  326.          virtual unsigned short ReportWarning(const char *text,
  327.                                               const unsigned short
  328.                                                  defaultChoice);
  329.  
  330.       private:
  331.          //data members
  332.          //------------
  333.          char *adFilename;   //name of file to which alerts will be reported
  334.          ofstream adFile;   //stream used to record alerts 
  335.  
  336.          //member functions
  337.          //----------------
  338.          void SetFilename(const char *filename);
  339.    };   //class TextFileAlertDriver
  340.  
  341.  
  342.  
  343. #if defined BORLAND_TV
  344.    class TurboVisionAlertDriver : public AlertDriver
  345.    {
  346.       public:
  347.          //constructor(s)
  348.          //--------------
  349.          TurboVisionAlertDriver(void);
  350.  
  351.          //destructor
  352.          //----------
  353.          virtual ~TurboVisionAlertDriver() {FreeMsgDialog();}
  354.  
  355.       protected:
  356.          //data members
  357.          //------------
  358.          TDialog     *adMsgDialog;   /*points to the dialog box used for
  359.                                        messages*/
  360.          TStaticText *adMsgText;     //points to text used for messages
  361.  
  362.          //member functions
  363.          //----------------
  364.          virtual void           FreeMsgDialog(void);
  365.          virtual void           FreeMsgText(void);
  366.          virtual TDialog*       InitMsgDialog(void);
  367.          virtual TStaticText*   InitMsgText(const TRect& bounds,
  368.                                             const char *text)
  369.                                    {return new TStaticText(bounds, text);}
  370.          virtual void           ReportError(const char *text);
  371.          virtual void           ReportInfo(const char *text);
  372.          virtual void           ReportMessage(const char *text);
  373.          virtual unsigned short ReportWarning(const char *text,
  374.                                               const unsigned short
  375.                                                  defaultChoice);
  376.    };   //class TurboVisionAlertDriver
  377. #endif   //BORLAND_TV
  378.  
  379.  
  380.  
  381. #ifdef TARGET_WINDOWS
  382.    class WindowsAlertDriver : public AlertDriver
  383.    {
  384.       public:
  385.          //constructor(s)
  386.          //--------------
  387.          WindowsAlertDriver(const HWND hParentWnd = NULL);
  388.  
  389.          //destructor
  390.          //----------
  391.          ~WindowsAlertDriver() {FreeMsgWindow();}
  392.  
  393.          //member functions
  394.          //----------------
  395.          HWND GetParent(void) {return hWndParent;}
  396.          void SetParent(HWND hParentWnd) {hWndParent = hParentWnd;}
  397.          
  398.          //platform-specific member functions
  399.          //----------------------------------
  400.          #ifdef BORLAND_CONTAIN
  401.             virtual char* nameOf() const {return "WindowsAlertDriver";}
  402.          #endif   //BORLAND_CONTAIN
  403.  
  404.       protected:
  405.          //data members
  406.          //------------
  407.          HWND hWndMsgText,     //handle to the message text
  408.               hWndMsgWindow,   //handle to the message window
  409.               hWndParent;      /*handle to the parent window of windows created
  410.                                  by this object*/
  411.  
  412.          //member functions
  413.          //----------------
  414.          virtual void           FreeMsgWindow(void);
  415.          virtual HWND           InitMsgWindow(void)
  416.                                    {return WindowsInitMessage(hWndParent);}
  417.          virtual void           ReportError(const char *text);
  418.          virtual void           ReportInfo(const char *text);
  419.          virtual void           ReportMessage(const char *text);
  420.          virtual unsigned short ReportWarning(const char *text,
  421.                                               const unsigned short
  422.                                                  defaultChoice);
  423.    };   //class WindowsAlertDriver
  424.  
  425.  
  426.  
  427.    #ifdef BORLAND_OWL
  428.       class BWCCAlertDriver : public WindowsAlertDriver
  429.       {
  430.          public:
  431.             //platform-specific member functions
  432.             //----------------------------------
  433.             #ifdef BORLAND_CONTAIN
  434.                virtual char* nameOf() const {return "BWCCAlertDriver";}
  435.             #endif   //BORLAND_CONTAIN
  436.  
  437.          protected:
  438.             //member functions
  439.             //----------------
  440.             virtual void           ReportError(const char *text);
  441.             virtual void           ReportInfo(const char *text);
  442.             virtual unsigned short ReportWarning(const char *text,
  443.                                                  const unsigned short
  444.                                                     defaultChoice);
  445.       };   //class BWCCAlertDriver
  446.    #endif   //BORLAND_OWL
  447.  
  448.  
  449.  
  450. #endif   //TARGET_WINDOWS
  451.  
  452.  
  453.  
  454.    //variable(s)
  455.    //-----------
  456.    extern AlertDriver *defaultAlertDriver;   //the default AlertDriver
  457.  
  458.  
  459.  
  460. #endif   //!ALERTDRV_H
  461.